package com.yc.forum.dao;

import com.yc.forum.util.DBHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ReplyDao {

    public static void main(String[] args) {
        ReplyDao r=new ReplyDao();
        System.out.println(r.putOneReply("1","121314","这是一套测是皮革"));
    }
    public int putOneReply(String postid,String account,String body){
        String sql="insert into reply(postid,account,body) values(?,?,?)";
        return DBHelper.update(sql,postid,account,body);
    }
    /**
     *查询文章下面的回复(回复内容+回复人信息)，分页
     *
     * 更具时间排序
     * @param postId    帖子id
     * @param begin     起始位置    mysql 有： 0位置
     * @param size      查询个数
     * @return
     */
    public List<Map<String,Object>> selectReplyWithLimitOrderByTime(String postId, int begin, int size){
        String sql="select * from reply,user where reply.postid=? and reply.account=user.account order by begintime DESC limit ?,?";
        List<Object> params=new ArrayList<>();
        params.add(postId);
        params.add(begin);
        params.add(size);
        List<Map<String,Object>>list= DBHelper.selectListMap(sql,params.toArray());
        return list;
    }
    //查询一条帖子的所有评论总计
    public int selectReplySum(String postId){
        String sql="select * from reply where postid=?";

        return Integer.parseInt(String.valueOf(DBHelper.count(sql,postId)));
    }
}
